package springboot.app.web ;

import javax.servlet.http.HttpServletRequest ;
import javax.servlet.http.HttpServletResponse ;
import javax.servlet.http.HttpSession ;

import org.springframework.web.bind.annotation.GetMapping ;
import org.springframework.web.bind.annotation.PathVariable ;
import org.springframework.web.bind.annotation.RestController ;

/**
 * 测试分布式共享session Controller
 * @author 80002165 @date 2017年7月6日 上午9:44:00
 */
@RestController
public class DistributeSessionController {
    
    @GetMapping("/test/distribute-session/get/{key}")
    public String returnSessionValue(HttpServletRequest request, HttpServletResponse response, @PathVariable("key") String key) {
        //获取分布式session
//        String sid = CookieUtil.getCookieValue(request, RedisConfig.SESSION_DISTRIBUTED_SESSIONID) ;
//        HttpServletRequestWrapper ourRequest = new HttpServletRequestWrapper(sid, request, response) ;
//        HttpSession session = ourRequest.getSession() ;
        HttpSession session = request.getSession() ;
        String value = (String) session.getAttribute(key) ;
        if(value == null){
            session.setAttribute(key, "no value");
        }
        return value ;
    }
}
